{snippet comment}
  {if $presenter->user->isLoggedIn()}
    {form commentForm class=>ajax-form}
      <ul class="errors" n:if="$form->hasErrors()">
          <li n:foreach="$form->errors as $error">{$error}</li>
      </ul>
      
      <div class="form form-row">
        {input text class=>array(form, form-text-area)}
      </div>
      
      <div class="button-row center">
        {input send class=>array(button, standard)}
      </div>
    {/form}
  {else}
    Abyste mohli psát své názory, musíte se přihlásit
  {/if}
  
  <div class="comment-list">
    {foreach $comments as $comment}
      <div class="comment-detail">
        <p class="image">
          {if $comment->getUser()->getPhoto() != "" && $comment->getUser()->getPhoto() != NULL}
            <img src="{$basePath}/content/users/{$comment->getUser()->getPhoto()}/image.jpg" width="70" height="70">
          {else}
            <img src="{$basePath}/www/images/user-photo.jpg" width="70" height="70">
          {/if}
        </p>
        <p class="content">
          <strong>
            <a href="{plink User:detail userId=>$comment->getUser()->getId()}">{$comment->getUser()->getLogin()}</a>
            {if $comment->getUser()->getLevel()} ({$comment->getUser()->getLevel()}){/if}
          </strong>
          <span class="comment-date"> - {$comment->getPublished()->format('d.m.Y H:i:s')}</span>
        </p>
        <p>{$comment->getContent()}</p>
        <div class="reset"></div>
      </div>
    {/foreach}
  </div>
  
  <div class="comments-pagination">
    {if $offset != 0}
      <a class="ajax left" n:href="page! offset=>$offset-$limit"></a>
    {else}
      <a class="ajax left pasive" href="#"></a>
    {/if}
    
    <span>{$currentPage + 1} / {$pagesTotal + 1}</span>
    
    {if ($offset + $limit) < $commentsCount}
      <a class="ajax right" n:href="page! offset=>$offset+$limit"></a>
    {else}
      <a class="ajax right pasive" href="#"></a>
    {/if}
  </div>
  
  <script>
  $(document).ready(function(){
    var process = false;
    jQuery.ajaxSetup({
      cache: false,
      dataType: 'json',
      success: function (payload) {
        process = false;
        if (payload.snippets) {
          for (var i in payload.snippets) {
            $('#' + i).html(payload.snippets[i]);
          }
        }
      },

      fail: function(error){
       process = false;
      }
    });

    $('.ajax').click(function (event) {
      event.preventDefault();
      $.post($(this).attr('href'), $(this).serialize());
    });
   
    $('.ajax-form').submit(function (event) {
      event.preventDefault();
      if(process === true){
        return;
      }
      process = true;
      $.post($(this).attr('action'), $(this).serialize());
    });
  });
  
  </script>
  
{/snippet}

